home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 19 / Mac Magazin and MacEasy Magazine CD - Issue 19.iso / Online / HttpServerƒ / •HTTP Server / TGMT.cp < prev    next >
Text File  |  1996-01-03  |  2KB  |  56 lines

  1. //    TGmt.cp - G M Time class object
  2. // 
  3. // Apple Macintosh Developer Technical Support
  4. // Written by:  Vinne Moscaritolo
  5. //
  6. //  Copyright (work in progress)  Apple Computer, Inc All rights reserved.
  7. //
  8. // You may incorporate this sample code into your applications without
  9. // restriction, though the sample code has been provided "AS IS" and the
  10. // responsibility for its operation is 100% yours.  However, what you are
  11. // not permitted to do is to redistribute the source as "DSC Sample Code"
  12. // after having made changes. If you're going to re-distribute the source,
  13. // we require that you make it clear in the source that the code was
  14. // descended from Apple Sample Code, but that you've made changes.
  15. // 
  16.  
  17. #include "TGMT.h"
  18. #include <iomanip.h>
  19. #include <OSUtils.h>
  20.  
  21. void TGmt::Now()
  22. {
  23.     GetDateTime(&fTime);
  24. };
  25.  
  26. unsigned long  TGmt::Elapsed()
  27. {
  28.     unsigned long    now;
  29.     GetDateTime(&now);
  30.     return (now - fTime);
  31. };
  32.  
  33. ostream &operator<< (ostream& s, const TGmt& t)
  34. {
  35.     const char*    wkday[]= {"XXX","Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
  36.     const char*    month[] = {"XXX","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
  37.     DateTimeRec d;
  38.     MachineLocation loc;
  39.     long         delta;
  40.     long        savedflags;
  41.     
  42. // normalize for GMT
  43.     ReadLocation(&loc);
  44.     delta = 0x00FFFFFF & loc.u.gmtDelta;
  45.     if(delta & 0x00800000) delta |= 0xff000000;
  46.     
  47. // Convert to Stream
  48.     SecondsToDate(t.fTime - delta ,&d);
  49.     savedflags = s.setf(ios::right, ios::adjustfield);
  50.     s << setfill('0');
  51.     s << wkday[ d.dayOfWeek ] << ", " << setw(2) <<  d.day << " " << month[d.month]  << " " << setw(4) << d.year << " ";
  52.     s << setw(2) << d.hour << ":" << setw(2) << d.minute << ":" << setw(2) << d.second <<" GMT";
  53.     s.setf(savedflags);
  54.     return s;
  55. };
  56.